<template>
	<view class="content">
		<view class="title">子组件B</view>
		<view class="b-box">
			comA组件传进来的值：
			<text class="intent-text-box">{{result}}</text>
		</view>
		<view class="b-box" style="margin: 10rpx;">
			<text>回传值：</text>
			<input type="text" v-model="callbackValue" style="color: yellow;" />
			<button @click="sendOutside()" size="mini">回传</button>
		</view>
	</view>
</template>

<script>
	export default {
		name: "comB",
		data() {
			return {
				result: '',
				callbackValue: ''
			};
		},
		methods: {
			sendOutside() {
				console.log("comB 回传值：", this.callbackValue);
				this.$emit('callBackFun', this.callbackValue);
			},
		},
		created() {
			uni.$on('getIntent', (msg) => {
				console.log("-----CompB-----getIntent----->" + msg);
				this.result = msg;
			});
		}
	}
</script>

<style>
	.content {
		background-color: #55c57a;
		padding: 20rpx;
		border-radius: 20rpx;
		margin: 10rpx 0;
	}

	.b-box {
		display: flex;
		align-items: center;
		margin: 10rpx 0;
	}

	.intent-text-box {
		background-color: #fff;
		color: #000;
		padding: 4rpx 8rpx;
		border-radius: 4rpx;
	}
</style>